<?php

// $Id$


require_once($WSC->get_site_inc_dir().'modules/admin_panel/site_admin_page_w_fctrl_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/admin_panel/forms/user_chpwd/user_chpwd_form_ctrl.class.php');



class User_Chpwd_WP extends Site_Admin_Page_W_FCtrl_UA {
	protected function create_form_ctrl() {
		$dbc = $this->get_dbc();
		$tvm = $this->get_tvm();

	 	$config = $this->get__config();
		$user_auth_config_loader_file = new User_Auth_Config_Loader_File($config->get_hidden_dir().'conf/'.TANGRA_MACHINE_SPECIFIC_CONF_FILENAME);	 	
		
		$ret = new User_Chpwd_Form_Ctrl('user_chpwd', $tvm, $dbc, 'obj_id', $user_auth_config_loader_file->get_user_dbc_class());

		return $ret;
	}


	protected function on_add_new() {
		throw new Tangra_User_Exception('Cannot add this type of records.');
//		$this->form_ctrl->set_permanent_external_param('add_new', 1);
//		$this->export('add_new', 1);
	}


	protected function on_received_id($object_id) {
		$dbc = $this->get_dbc();

		$user = new User_DBC();
		$dbc = $this->get_dbc();
		if ($user->load_by_id($dbc, $object_id)) {
			$this->export('username', $user->get_username());
		} else {
			throw new Tangra_User_Exception('Cannot find user with id = '.$object_id);
		}
	}


	protected function on_submit_processed_ok() {
		$user = $this->form_ctrl->get_object();
		$ua_config = $this->get_ua_config();

		$svm = $this->get_svm();
		$current_user = $svm->get_global_var($ua_config['session_var_name']);
		if ($user->get_username() == $current_user->get_username()) {
			$svm->set_global_var($ua_config['session_var_name'], $user);
		}
	}
}